package com.geekchique.runningbuddy.activity;

import com.geekchique.runningbuddy.R;
import com.geekchique.runningbuddy.R.id;
import com.geekchique.runningbuddy.R.layout;
import com.geekchique.runningbuddy.R.string;
import com.geekchique.runningbuddy.activity.stopclock.StopClock;
import com.geekchique.runningbuddy.provider.ActivityID;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.Menu.Item;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Home extends Activity {
    
	@Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.home);
        
        Button gotoStopClock = (Button)findViewById(R.id.goto_stopclock);
        gotoStopClock.setOnClickListener(gotoStopClockListener);

        Button gotoToday = (Button)findViewById(R.id.goto_today);
        gotoToday.setOnClickListener(gotoTodayListener);

        Button gotoPastJogs = (Button)findViewById(R.id.goto_journal);
        gotoPastJogs.setOnClickListener(gotoPastJogsListener);
        
        Button gotoHelp = (Button)findViewById(R.id.goto_help);
        gotoHelp.setOnClickListener(gotoHelpListener);
    }
	
    @Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		menu.add(0, ActivityID.STOPCLOCK, R.string.goto_stopclock);
		menu.add(1, ActivityID.TODAYJOGS, R.string.goto_today);
		menu.add(2, ActivityID.PASTJOGS, R.string.goto_pastjogs);
		menu.add(3, ActivityID.JOGHELP, R.string.goto_help);
		
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(Item item) {
	    switch (item.getId()) {
	    
	    case ActivityID.STOPCLOCK:
	    	switchToStopClock();
	    	break;
	    	
	    case ActivityID.TODAYJOGS:
	    	switchToToday();
	    	break;
	    	
	    case ActivityID.PASTJOGS:
	    	switchToPastJogs();
	    	break;
	
		case ActivityID.JOGHELP:
			switchToHelp();
			break;
	
	    }
	    return super.onOptionsItemSelected(item);
	}

	private void switchToStopClock() {
	      Intent i = new Intent(this, StopClock.class);
	      startSubActivity(i, ActivityID.STOPCLOCK);	
	}

	private void switchToHelp() {
	    Intent i = new Intent(this, Help.class);
	    startSubActivity(i, ActivityID.JOGHELP);
	}

	private void switchToToday() {
	    Intent i = new Intent(this, Today.class);
	    startSubActivity(i, ActivityID.TODAYJOGS);	
	}

	private void switchToPastJogs() {
	    Intent i = new Intent(this, PastJogs.class);
	    startSubActivity(i, ActivityID.PASTJOGS);
	}

	private OnClickListener gotoStopClockListener = new OnClickListener()
    {
    	public void onClick(View v)
        {
    		switchToStopClock();
        }
    };
    
    private OnClickListener gotoTodayListener = new OnClickListener()
    {
    	public void onClick(View v)
        {
    		switchToToday();
        }
    };
    
    private OnClickListener gotoPastJogsListener = new OnClickListener()
    {
    	public void onClick(View v)
    	{
    		switchToPastJogs();
    	}
    };
    
    private OnClickListener gotoHelpListener = new OnClickListener()
    {
    	public void onClick(View v)
    	{
    		switchToHelp();
    	}
    };

    
}